<template>
	<view>
		<text>我的</text>
		<button type="default" @click="handleLogin">登录</button>
		<button type="default" open-type="chooseAvatar" @chooseavatar="handleChoose">选择头像</button>
		<input type="nickname"  >
		<button type="default" @click="handleSubmit">确定</button>
		<image :src="avatarUrl" mode=""></image>
	</view>
</template>

<script>
	import {login,fillDetail} from '../../services/user.js'
	export default {
		data() {
			return {
				image:"",
				avatarUrl:""
			}
		},
		methods: {
			handleLogin(){
				uni.login({
				  provider: 'weixin',
				  success: async (loginRes) => {
				    console.log("loginRes:",loginRes);
					let res = await login(loginRes.code);
					console.log("res:",res);
				    // 获取用户信息
				    uni.getUserInfo({
				      provider: 'weixin',
				      success:  (infoRes) => {
				        console.log('用户昵称为：' + infoRes.userInfo.nickName);
						this.avatarUrl = infoRes.userInfo.avatarUrl;
						console.log("infoRes:",infoRes);
				      }
				    });
					
				  }
				});
			},
			async handleChoose(e){
				console.log(e.detail.avatarUrl);
				this.image = wx.getFileSystemManager().readFileSync(e.detail.avatarUrl,'base64')
				this.avatarUrl = e.detail.avatarUrl
				console.log(this.image);
				
				// console.log("data",data);
			},
			async handleSubmit(){
				let data = await fillDetail({image:this.image});
				// console.log(this.image);
			}
		}
	}
</script>

<style>

</style>
